using System.Data;

namespace Chaotic.DataBase.DataAccess
{
	public sealed class QueryParameter
	{
		private string _mParameterName;

		private object? _mValue;

		public string ParameterName
		{
			get
			{
				return _mParameterName;
			}
			set
			{
				_mParameterName = value;
			}
		}

		public object? Value
		{
			get
			{
				return _mValue;
			}
			set
			{
				_mValue = value;
			}
		}

		public ParameterDirection Direction { get; set; }

		public object DbType { get; set; }

		public QueryParameter(string? parameterName, object? value)
		{
			Init(parameterName, value);
			Direction = ParameterDirection.Input;
		}

		public QueryParameter(string? parameterName, object? value, ParameterDirection direction)
		{
			Init(parameterName, value);
			Direction = direction;
		}

		public QueryParameter(string? parameterName, object? value, string? dbType, ParameterDirection direction)
		{
			Init(parameterName, value);
			Direction = direction;
			DbType = PersistenceProperty.GetDbTypeEunm[PersistenceProperty.DatabaseType].GetTypeEnum(dbType);
		}

		private void Init(string? ParameterName, object? Value)
		{
			if (PersistenceProperty.DatabaseType == DatabaseType.Oracle)
			{
                _mParameterName = ParameterName.Replace("@", ":");
                _mValue = Value; 
			}
			else
			{
                _mParameterName = ParameterName.Replace(":", "@");
                _mValue = Value;
            }
		}
	}
}